//
//  ViewController.m
//  WeiDuYY
//
//  Created by 王克杨的Mac on 2019/1/23.
//  Copyright © 2019 W ke杨. All rights reserved.
//

#import "ViewController.h"
#import "MeViewController.h"
#import "CinemaViewController.h"
#import "FilmViewController.h"
@interface ViewController ()
@property(nonatomic,strong) NSMutableArray *VCarr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //
    
    self.navigationItem.title=@"543";
    //未选中图片
    NSArray *arr = @[@"com_icon_film_fault_hdpi",@"com_icon_cinema_default_hdpi",@"com_icon_my_default_hdip"];
    //选中图片
    NSArray *uarr=@[@"com_icon_film_selected.hdpi",@"com_icon_cinema_selected_hdpi",@"com_icon_my_selected_hdpi"];
    //控制器名称
    NSArray *VCarr = @[@"FilmViewController",@"CinemaViewController",@"MeViewController"];
    NSMutableArray *MutableArr = [[NSMutableArray alloc]init];
    for (int i = 0; i<VCarr.count; i++) {
        UIViewController *vc = [[NSClassFromString(VCarr[i])alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        nav.tabBarItem.image = [UIImage imageNamed:arr[i]];
        nav.tabBarItem.selectedImage = [UIImage imageNamed:uarr[i]];
//        nav.tabBarItem.title = arr[i];
        

        //覆盖原生Tabbar的上横线
          [[UITabBar appearance] setShadowImage:[self createImageWithColor:[UIColor clearColor]]];
        //背景图片为透明色
         [[UITabBar appearance] setBackgroundImage:[self createImageWithColor:[UIColor clearColor]]];
        self.tabBar.backgroundColor = [UIColor clearColor];
        //设置为半透明
        self.tabBarController.tabBar.translucent = YES;
        
        [MutableArr addObject:nav];
    }
    
    self.viewControllers = MutableArr;
    
}

//tabbar自定义方法 设置为透明
-(UIImage*) createImageWithColor:(UIColor*) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

@end
